import App from './App'
import VueI18n from 'vue-i18n'
import routerConfig from './routers'
import { Vue, VueRouter } from '../../../static/h5/config/main'
import handlewechat from '../../../static/h5/utils/handlewechat'
import { isWexinClient } from './utils/util'
import fullpage from './directives/fullpage'
import animate from './directives/animate'
// import VueFullpage from './vue-fullpage'

Vue.directive('fullpage', fullpage)
Vue.directive('animate', animate)
// Vue.use(VueFullpage)
Vue.use(VueI18n, {
  lang: 'zh_cn',
  locales: require('./locales')
})

const router = new VueRouter({
  hashbang: true,
  history: false,
  saveScrollPosition: true
}).map(routerConfig)

router.beforeEach(function (transition) {
  if (transition.to.path) {
    if (isWexinClient()) {
      handlewechat.init(new Vue())
    }
    transition.next()
  }
})

Vue.http.interceptors.push({
  request: function (request) {
    return request
  },
  response: function (response) {
    const status = response.status
    if (status !== 200) {
      let message = ''
      if (status === 401) {
        message = '没有权限'
        window.alert(message)
        return
      }
    }
    return response
  }
})
// Define your root component for app here
router.start(App, '#app')
